package com.androidhive.xmlparsing;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CityListViewAdapter extends BaseAdapter {

	 private Activity activity;
	    private ArrayList<String> data;
	    private static LayoutInflater inflater =null;
	    public CityListViewAdapter(Activity a,  ArrayList<String> d) {
	        activity = a;
	        data=d;
	        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	    }
	    
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		 return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.city, null);
 
        TextView city = (TextView)vi.findViewById(R.id.city);
        String item ;
        item = data.get(position);
 
        //Setting all values in listview
        city.setText(item);
        return vi;
	}

}
